package com.zmc.lostfound.system.controller;

import com.zmc.lostfound.common.utils.PageParams;
import com.zmc.lostfound.common.utils.PageResult;
import com.zmc.lostfound.common.utils.Result;
import com.zmc.lostfound.common.valid.AddGroup;
import com.zmc.lostfound.common.valid.UpdateGroup;
import com.zmc.lostfound.system.entity.NoticeEntity;
import com.zmc.lostfound.system.vo.NoticeSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.zmc.lostfound.system.service.NoticeService;

import java.util.List;

/**
 * @author ZMC
 * @email 2869581855@qq.com
 * @date 2023-07-05 15:36:51
 */
@RestController
@RequestMapping("/notice")
@Api(value = "系统公告管理接口", tags = "系统公告管理接口")
public class NoticeController {

    private final NoticeService noticeService;

    public NoticeController(NoticeService noticeService) {
        this.noticeService = noticeService;
    }

    @ApiOperation("分页模糊查询系统公告")
    @PostMapping("/query/page")
    public Result queryPage(@RequestBody @Validated PageParams pageParams) {
        PageResult pageResult = noticeService.queryPage(pageParams);
        return Result.ok("查询成功").put("pageResult", pageResult);
    }

    @ApiOperation("根据主键id查询系统公告")
    @GetMapping("/query/info/{id}")
    public Result queryInfoById(@PathVariable("id") Long id) {
        NoticeEntity noticeInfo = noticeService.queryInfoById(id);
        return Result.ok("查询成功").put("noticeInfo", noticeInfo);
    }

    @ApiOperation("查询全部系统公告")
    @GetMapping("/query/all")
    public Result queryAll() {
        List<NoticeEntity> noticeInfoList = noticeService.findAll();
        return Result.ok("查询成功").put("noticeInfoList", noticeInfoList);
    }

    @ApiOperation("新增系统公告")
    @PostMapping("/insertNotice")
    public Result insertNotice(@RequestBody @Validated(value = {AddGroup.class}) NoticeSaveVO noticeSaveVO) {
        return noticeService.insertNotice(noticeSaveVO);
    }

    @ApiOperation("修改系统公告")
    @PutMapping("/updateNotice")
    public Result updateNotice(@RequestBody @Validated(value = {UpdateGroup.class}) NoticeSaveVO noticeSaveVO) {
        return noticeService.updateNotice(noticeSaveVO);
    }

    @ApiOperation("批量删除系统公告")
    @DeleteMapping("/deleteBatchByIds")
    public Result deleteBatchByIds(@RequestBody List<Long> ids) {
        return noticeService.deleteBatchNotice(ids);
    }

}
